/*
 * Copyright 2022 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "lvgl/lvgl.h"
#include "gui_guider.h"

void ui_init_style(lv_style_t * style)
{
  if (style->prop_cnt > 1)
    lv_style_reset(style);
  else
    lv_style_init(style);
}

void init_scr_del_flag(lv_ui *ui)
{
	ui->blueCounter_del = true;
}

void setup_ui(lv_ui *ui)
{		
	init_scr_del_flag(ui);
	
	//0.Write codes full_background
	ui->cont_background = lv_obj_create(NULL);
	lv_obj_set_size(ui->cont_background, 480, 272);

	//Write style for full_background, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
	lv_obj_set_style_bg_opa(ui->cont_background, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(ui->cont_background, lv_color_hex(0x599cc7), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_grad_dir(ui->cont_background, LV_GRAD_DIR_VER, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_grad_color(ui->cont_background, lv_color_hex(0x8dcdeb), LV_PART_MAIN|LV_STATE_DEFAULT);

	//1.Write codes cont_front
	ui->cont_front = lv_obj_create(ui->cont_background);
	lv_obj_set_pos(ui->cont_front, 4, 4);
	lv_obj_set_size(ui->cont_front, 473, 265);
	lv_obj_set_scrollbar_mode(ui->cont_front, LV_SCROLLBAR_MODE_OFF);

	//Write style for cont_front, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
	lv_obj_set_style_border_width(ui->cont_front, 4, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_border_opa(ui->cont_front, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_border_color(ui->cont_front, lv_color_hex(0xacceea), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_border_side(ui->cont_front, LV_BORDER_SIDE_FULL, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_radius(ui->cont_front, 12, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_opa(ui->cont_front, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(ui->cont_front, lv_color_hex(0xffffff), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_grad_dir(ui->cont_front, LV_GRAD_DIR_VER, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_grad_color(ui->cont_front, lv_color_hex(0x4e95cb), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_top(ui->cont_front, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_bottom(ui->cont_front, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_left(ui->cont_front, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_right(ui->cont_front, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_shadow_width(ui->cont_front, 0, LV_PART_MAIN|LV_STATE_DEFAULT);

	//2.Write codes label_title
	ui->label_title = lv_label_create(ui->cont_front);
	lv_label_set_text(ui->label_title, "Snoring Detection Demo");
	lv_label_set_long_mode(ui->label_title, LV_LABEL_LONG_WRAP);
	lv_obj_set_pos(ui->label_title, 90, 21);
	lv_obj_set_size(ui->label_title, 224, 23);

	//Write style for label_title, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
	lv_obj_set_style_text_color(ui->label_title, lv_color_hex(0x000000), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->label_title, &lv_font_Acme_Regular_16, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_letter_space(ui->label_title, 2, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_line_space(ui->label_title, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->label_title, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);

	//3.Write codes btn_begin and its label
	ui->btn_begin = lv_btn_create(ui->cont_front);
	ui->btn_begin_label = lv_label_create(ui->btn_begin);
	lv_label_set_text(ui->btn_begin_label, "Begin");
	lv_label_set_long_mode(ui->btn_begin_label, LV_LABEL_LONG_WRAP);
	lv_obj_align(ui->btn_begin_label, LV_ALIGN_CENTER, 0, 0);
	lv_obj_set_pos(ui->btn_begin, 392, 13);
	lv_obj_set_size(ui->btn_begin, 47, 33);

	//Write style for btn_begin
	lv_obj_set_style_bg_opa(ui->btn_begin, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(ui->btn_begin, lv_color_hex(0xb0b0b1), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_radius(ui->btn_begin, 5, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_color(ui->btn_begin_label, lv_color_hex(0xffffff), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->btn_begin_label, &lv_font_montserratMedium_14, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->btn_begin_label, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);
	
	//4.Write codes label_sensitivity
	ui->label_sensitivity = lv_label_create(ui->cont_front);
	lv_label_set_text(ui->label_sensitivity, "Sensitivity:");
	lv_label_set_long_mode(ui->label_sensitivity, LV_LABEL_LONG_WRAP);
	lv_obj_set_pos(ui->label_sensitivity, 60, 95);
	lv_obj_set_size(ui->label_sensitivity, 110, 20);
	lv_obj_set_style_text_color(ui->label_sensitivity, lv_color_hex(0x000080), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->label_sensitivity, &lv_font_montserratMedium_14, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_top(ui->label_sensitivity, 2, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->label_sensitivity, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);
	
	//Write codes label_sen_num
	ui->label_sen_num = lv_label_create(ui->cont_front);
	lv_label_set_text(ui->label_sen_num, "50");
	lv_label_set_long_mode(ui->label_sen_num, LV_LABEL_LONG_WRAP);
	lv_obj_set_pos(ui->label_sen_num, 160, 95);
	lv_obj_set_size(ui->label_sen_num, 30, 20);
	lv_obj_set_style_text_color(ui->label_sen_num, lv_color_hex(0x8B0000), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->label_sen_num, &lv_font_montserratMedium_14, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_top(ui->label_sen_num, 2, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->label_sen_num, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);
	
	//Write codes label_sen_pct
	ui->label_sen_pct = lv_label_create(ui->cont_front);
	lv_label_set_text(ui->label_sen_pct, "%");
	lv_label_set_long_mode(ui->label_sen_pct, LV_LABEL_LONG_WRAP);
	lv_obj_set_pos(ui->label_sen_pct, 200, 95);
	lv_obj_set_size(ui->label_sen_pct, 30, 20);
	lv_obj_set_style_text_color(ui->label_sen_pct, lv_color_hex(0x000080), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->label_sen_pct, &lv_font_montserratMedium_14, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_top(ui->label_sen_pct, 2, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->label_sen_pct, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);
	
	//5.Write codes label_confidence
	ui->label_confidence = lv_label_create(ui->cont_front);
	lv_label_set_text(ui->label_confidence, "Result Area");
	lv_label_set_long_mode(ui->label_confidence, LV_LABEL_LONG_WRAP);
	lv_obj_set_style_text_color(ui->label_confidence, lv_color_hex(0x000080), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->label_confidence, &lv_font_Acme_Regular_16, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_pos(ui->label_confidence, 260, 95);
	lv_obj_set_size(ui->label_confidence, 110, 20);
	lv_obj_set_style_radius(ui->label_confidence, 10, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(ui->label_confidence, lv_color_hex(0x00cca2), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_opa(guider_ui.label_confidence, 102, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_top(ui->label_confidence, 2, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->label_confidence, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);
	
	//Write codes label_con_num
	ui->label_con_num = lv_label_create(ui->cont_front);
	lv_label_set_text(ui->label_con_num, " ");
	lv_label_set_long_mode(ui->label_con_num, LV_LABEL_LONG_WRAP);
	lv_obj_set_pos(ui->label_con_num, 370, 95);
	lv_obj_set_size(ui->label_con_num, 30, 20);
	lv_obj_set_style_text_color(ui->label_con_num, lv_color_hex(0x8B0000), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->label_con_num, &lv_font_montserratMedium_14, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_top(ui->label_con_num, 2, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->label_con_num, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);
	
	//Write codes label_con_pct
	ui->label_con_pct = lv_label_create(ui->cont_front);
	lv_label_set_text(ui->label_con_pct, " ");
	lv_label_set_long_mode(ui->label_con_pct, LV_LABEL_LONG_WRAP);
	lv_obj_set_pos(ui->label_con_pct, 400, 95);
	lv_obj_set_size(ui->label_con_pct, 30, 20);
	lv_obj_set_style_text_color(ui->label_con_pct, lv_color_hex(0x000080), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->label_con_pct, &lv_font_montserratMedium_14, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_top(ui->label_con_pct, 2, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->label_con_pct, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);

	//6.Write codes for slider_sensitivity
	ui->slider_sensitivity = lv_slider_create(ui->cont_front);
	lv_slider_set_range(ui->slider_sensitivity, 0, 100);
	lv_slider_set_mode(ui->slider_sensitivity, LV_SLIDER_MODE_SYMMETRICAL);
	lv_slider_set_value(ui->slider_sensitivity, 50, LV_ANIM_OFF);
	lv_obj_set_pos(ui->slider_sensitivity, 20, 65);
	lv_obj_set_size(ui->slider_sensitivity, 8, 160);

	//Write style for slider_sensitivity, Part: LV_PART_MAIN
	lv_obj_set_style_bg_opa(ui->slider_sensitivity, 128, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(ui->slider_sensitivity, lv_color_hex(0x2195f6), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_radius(ui->slider_sensitivity, 50, LV_PART_MAIN|LV_STATE_DEFAULT);

	//Write style for slider_sensitivity, Part: LV_PART_INDICATOR
	lv_obj_set_style_bg_opa(ui->slider_sensitivity, 255, LV_PART_INDICATOR|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(ui->slider_sensitivity, lv_color_hex(0x1665a7), LV_PART_INDICATOR|LV_STATE_DEFAULT);
	lv_obj_set_style_radius(ui->slider_sensitivity, 50, LV_PART_INDICATOR|LV_STATE_DEFAULT);

	//Write style for slider_sensitivity, Part: LV_PART_KNOB
	lv_obj_set_style_bg_opa(ui->slider_sensitivity, 255, LV_PART_KNOB|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(ui->slider_sensitivity, lv_color_hex(0x1665A7), LV_PART_KNOB|LV_STATE_DEFAULT);
	lv_obj_set_style_radius(ui->slider_sensitivity, 50, LV_PART_KNOB|LV_STATE_DEFAULT);

	//7.Write style for rolling_mel
	ui->rolling_mel = lv_img_create(ui->cont_front);
	lv_img_set_src(ui->rolling_mel, &MelSG);
	lv_img_set_pivot(ui->rolling_mel, 50,50);
	lv_img_set_angle(ui->rolling_mel, 0);
	lv_obj_set_pos(ui->rolling_mel, 62, 160);
	lv_obj_set_size(ui->rolling_mel, 320, 64);
	
	//8.green LED
	ui->green_led = lv_led_create(ui->cont_front);
	lv_led_set_brightness(ui->green_led, 255);
	lv_led_set_color(ui->green_led, lv_color_hex(0x00FF00));
	lv_obj_set_pos(ui->green_led, 412, 150);
	lv_obj_set_size(ui->green_led, 20, 20);
	lv_led_off(guider_ui.green_led);

	//9.Red LED
	ui->red_led = lv_led_create(ui->cont_front);
	lv_led_set_brightness(ui->red_led, 255);
	lv_led_set_color(ui->red_led, lv_color_hex(0xFF0000));
	lv_obj_set_pos(ui->red_led, 412, 210);
	lv_obj_set_size(ui->red_led, 20, 20);
	lv_led_off(guider_ui.red_led);
	
	//10.label_snoring
	ui->label_snoring = lv_label_create(ui->cont_front);
	lv_label_set_text(ui->label_snoring, " ");
	lv_label_set_long_mode(ui->label_snoring, LV_LABEL_LONG_WRAP);
	lv_obj_set_pos(ui->label_snoring, 294, 65);
	lv_obj_set_size(ui->label_snoring, 110, 20);

	//Write style for label_snoring, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT
	lv_obj_set_style_radius(ui->label_snoring, 10, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_color(ui->label_snoring, lv_color_hex(0xff0027), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(ui->label_snoring, &lv_font_Acme_Regular_16, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_text_align(ui->label_snoring, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_opa(ui->label_snoring, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(ui->label_snoring, lv_color_hex(0xff0027), LV_PART_MAIN|LV_STATE_DEFAULT);
	lv_obj_set_style_pad_top(ui->label_snoring, 2, LV_PART_MAIN|LV_STATE_DEFAULT);
	
  lv_scr_load(ui->cont_background);
}
